

'use strict';
const express=require('express');
const path=require('path');
const xtpl=require('xtpl');
const moment=require('moment');

const db=require(path.join(__dirname,"../configs/database.js"));
const base=require(path.join(__dirname,"./baseController.js"));

module.exports.informList=function(req,res){

 const page=parseInt(req.query.page||'1');
 const limit=parseInt(req.query.limit||'12');

 const start=(page-1)*limit;

 db.table('notice').count("*").then(function(count){

    const totalPage=count%limit==0?count/limit:parseInt(count/limit)+1;
    const totalPageArray=[];
    for(var i=1;i<=totalPage;i++){

    	totalPageArray.push(i);
    };
    
    db.table("notice").join("pre_teach on pre_notice.teach_id=pre_teach.teach_id").join("pre_class on pre_notice.class_id=pre_class.class_id").order("notice_id DESC").limit(start,limit).select().then(function(data){

   xtpl.renderFile(
         path.join(__dirname,"../views/admin/inform_list.html"),
         {

           
        array:data,
    	totalPage:totalPage,
        totalPageArray:totalPageArray,
        page:page


         },
         function(err,content){

              res.setHeader("Content-Type","text/html;charset=utf-8");
              res.end(content);
         }
   	);
        
    });

 });

};
